﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace System
{
    public static partial class StringExtension
    {
        /// <summary>
        /// 计算当前字符串的MD5哈希值
        /// </summary>
        /// <param name="this"></param>
        /// <returns></returns>
        public static string MD5(this string @this)
        {
            using (HashAlgorithm hashAlgorithm = System.Security.Cryptography.MD5.Create())
            {
                var result = hashAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(@this));
                return result.ToHexString();
            }
        }
        /// <summary>
        /// 计算当前字符串的SHA1哈希值
        /// </summary>
        /// <param name="this"></param>
        /// <returns></returns>
        public static string SHA1(this string @this)
        {
            using (var hash = System.Security.Cryptography.SHA1.Create())
            {
                var result = hash.ComputeHash(Encoding.UTF8.GetBytes(@this));
                return result.ToHexString();
            }
        }
        //TODO:添加DES解密与加密
        //TODO:添加与其他平台通用的DES加密与解码
    }
}
